package com.jx.gocomtask.webservice.restcontroller.base;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import phoenics.common.BaseData.BaseErrorCode;
import phoenics.common.BaseData.StatusData;
import phoenics.common.exception.AuthorizedException;
import phoenics.common.exception.NotFoundException;
import phoenics.common.exception.ParamsException;
import phoenics.common.exception.StatusException;

import org.springframework.http.HttpStatus;

@RestControllerAdvice
public class BaseRestController {
	//private static org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(BaseRestController.class);
	 
	 @ExceptionHandler(value = {AuthorizedException.class})
	 @ResponseStatus(HttpStatus.UNAUTHORIZED)
	 public StatusData handlerServerError(AuthorizedException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	 @ExceptionHandler(value = {ParamsException.class})
	 @ResponseStatus(HttpStatus.BAD_REQUEST)
	 public StatusData handlerServerError(ParamsException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	 @ExceptionHandler(value = {StatusException.class})
	 @ResponseStatus(HttpStatus.UNAUTHORIZED)
	 public StatusData handlerServerError(StatusException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	 @ExceptionHandler(value = {NotFoundException.class})
	 @ResponseStatus(HttpStatus.NOT_FOUND)
	 public StatusData handlerServerError(NotFoundException ex){
		 return new StatusData(ex.getCode(),ex.getMsg());
	 }
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 
	 @ExceptionHandler(value = {Exception.class})
	 @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
	 public StatusData handlerServerError(Exception ex){
		 ex.printStackTrace();
		 return new StatusData(BaseErrorCode.SERVER_ERROR,BaseErrorCode.SERVER_ERROR_MSG);
	 }
}
